const { parseXML } = require('../utils/xmlHelper');

// 解析XML请求体
const xmlBodyParser = async (req, res, next) => {
  if (req.is('text/xml')) {
    try {
      const result = await parseXML(req.body);
      req.wechat = result;
      next();
    } catch (error) {
      res.status(400).send('Invalid XML');
    }
  } else {
    next();
  }
};

module.exports = xmlBodyParser;